package com.vvv.designpattern.bridge.function;

import com.vvv.designpattern.bridge.abst.factory.RegisterLoginComponentFactory;
import com.vvv.designpattern.pojo.UserInfo;
import com.vvv.designpattern.repo.UserRepository;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * @author vvv
 * @date 2023-11-16 14 18
 * discription 右路的具体实现类，默认登录方案
 */
@Component
public class RegisterLoginByDefault
        extends AbstractRegisterLoginFunc implements RegisterLoginFuncInterface {
    // TODO 这里是否可以通过构造器注册的形式，直接调用父类的构造器将UserRepository传到父类中呢？
    @Resource
    private UserRepository userRepository;

    /**
     * PostConstruct注解可以在完成bean的注入后，立即调用标志为@PostConstruct的注解的方法
     */
    @PostConstruct
    public void initFuncMap() {
        RegisterLoginComponentFactory.funcMap.put("Default", this);
    }

    @Override
    public String login(String account, String password) {
        return super.commonLogin(account, password, userRepository);
    }

    @Override
    public String register(UserInfo userInfo) {
        return super.commonRegister(userInfo, userRepository);
    }

    @Override
    public boolean checkUserExists(String username) {
        return super.commonCheckUserExists(username, userRepository);
    }

}
